using System.Collections;

/*
    CssDom Library
    Copyright (C) 2007-2011  Ferenc Veres

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

namespace WPS.Modules.StyleLibrary
{
	/// <summary>
	/// IComparer implementation to sort ArrayList of StyleRuleSearch objects by RuleIndex.
	/// </summary>
	public class StyleRuleSearchComparer : IComparer
	{
		/// <summary>
		/// Creates a new comparer to sort ArrayList(.Sort) of StyleRuleSearch objects by RuleIndex.
		/// </summary>
		public StyleRuleSearchComparer()
		{
		}

		#region IComparer Members

		/// <summary>
		/// Compares two StyleRuleSearch objects' Rule Index and returns:
		/// -1 = x is less than y. 
		///  0 = equal (impossible with Rule Index)
		///  1 = x is greather than y.
		/// </summary>
		/// <param name="x">StyleRuleSearch Object to compare</param>
		/// <param name="y">StyleRuleSearch Object to compare</param>
		/// <returns>-1 if x is smaller, 1 if x is greater.</returns>
		public int Compare(object x, object y)
		{
			StyleRuleSearch xRule = (StyleRuleSearch)x;
			StyleRuleSearch yRule = (StyleRuleSearch)y;

			if(xRule.RuleIndex < yRule.RuleIndex)
			{
				return -1;
			}
			if(xRule.RuleIndex > yRule.RuleIndex)
			{
				return 1;
			}
			return 0;
		}

		#endregion
	}
}